#include "menupanel.h"

const int MenuPanel::ID_NEW_BUTTON=101;
const int MenuPanel::ID_LOAD_BUTTON=102;
const int MenuPanel::ID_HOWTO_BUTTON=103;
const int MenuPanel::ID_CREDITS_BUTTON=104;
const int MenuPanel::ID_QUIT_BUTTON=105;


MenuPanel::MenuPanel(wxFrame*frame,int id) : wxPanel(frame,id,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL,wxT("MenuPanel"))
{
    wxImage::AddHandler(new wxPNGHandler);
    this->SetBackgroundBitmap(wxBitmap(wxT("source\\flower.png"),wxBITMAP_TYPE_PNG));

    childpanel = new wxPanel(this,wxID_ANY,wxDefaultPosition,wxSize(250,600));
    childpanel->SetBackgroundBitmap(wxBitmap(wxT("source\\flower.png"),wxBITMAP_TYPE_PNG));

    wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);


    newbutton = new wxBitmapButton(childpanel,ID_NEW_BUTTON,wxBitmap(wxT("source\\newgame.png"),wxBITMAP_TYPE_PNG));
    loadbutton = new wxBitmapButton(childpanel,ID_LOAD_BUTTON,wxBitmap(wxT("source\\loadgame.png"),wxBITMAP_TYPE_PNG));
    howtobutton = new wxBitmapButton(childpanel,ID_HOWTO_BUTTON,wxBitmap(wxT("source\\howtogame.png"),wxBITMAP_TYPE_PNG));
    creditsbutton = new wxBitmapButton(childpanel,ID_CREDITS_BUTTON,wxBitmap(wxT("source\\howtogame.png"),wxBITMAP_TYPE_PNG));
    quitbutton = new wxBitmapButton(childpanel,ID_QUIT_BUTTON,wxBitmap(wxT("source\\quitgame.png"),wxBITMAP_TYPE_PNG));

    Connect(ID_QUIT_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MenuPanel::OnQuit));
    Connect(ID_CREDITS_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MenuPanel::OnCredits));
    Connect(ID_HOWTO_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MenuPanel::OnHowto));
    Connect(ID_LOAD_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MenuPanel::OnLoad));
    Connect(ID_NEW_BUTTON,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MenuPanel::OnNew));

    vbox->Add(newbutton,0,wxCENTER,10);
    vbox->Add(-1,20);
    vbox->Add(loadbutton,0,wxLEFT,10);
    vbox->Add(-1,20);
    vbox->Add(howtobutton,0,wxALIGN_RIGHT,10);
    vbox->Add(-1,20);
    vbox->Add(creditsbutton,0,wxLEFT,10);
    vbox->Add(-1,20);
    vbox->Add(quitbutton,0,wxALIGN_RIGHT,10);
    childpanel->SetSizer(vbox);

    hbox->Add(childpanel,1,wxALIGN_CENTER|wxCENTER,10);

    this->SetSizer(hbox);
}


void MenuPanel::OnQuit(wxCommandEvent&event)
{
    event.Skip();
//    this->GetParent()->Close(true);
}

void MenuPanel::OnCredits(wxCommandEvent&event)
{
    CreditsDialog *creditsdialog = new CreditsDialog(wxT("creditsdialog"));
    creditsdialog->Show(true);
}

void MenuPanel::OnHowto(wxCommandEvent&event)
{
    wxString howtostring = wxT("Cara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begituCara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begitu Cara bermain adalah begini begitu");
    wxMessageDialog *dial = new wxMessageDialog(NULL,howtostring,wxT("HowTo"),wxOK);
    dial->ShowModal();
}

void MenuPanel::OnLoad(wxCommandEvent&event)
{
    wxFileDialog *openFileDialog = new wxFileDialog(this);

    if (openFileDialog->ShowModal()==wxID_OK)
    {
        wxPuts(openFileDialog->GetPath());
        filename=openFileDialog->GetPath();
        //TODO check and play
    }
}


void MenuPanel::OnNew(wxCommandEvent&event)
{
    event.Skip();
}
